﻿using SmartSpace.Core;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SmartSpace.Organization
{
    public partial class OrganizationService : IOrganizationService
    {
        public ServiceResult SaveEmployee(Employee employee)
        {
            using (OrganizationDbContext context = new OrganizationDbContext())
            {
                if (!EntityRepository.SaveCodeEntity(employee, context))
                {
                    return new ServiceResult(false);
                }
                return new ServiceResult(EntityRepository.Commit(context));
            }
        }

        public ServiceResult DeleteEmployee(Guid id)
        {
            using (OrganizationDbContext context = new OrganizationDbContext())
            {
                if (!EntityRepository.DeleteCodeEntity<Employee>(id, context))
                {
                    return new ServiceResult(false);
                }
                return new ServiceResult(EntityRepository.Commit(context));
            }
        }

        public ServiceResult DeleteEmployee(string code)
        {
            using (OrganizationDbContext context = new OrganizationDbContext())
            {
                if (!EntityRepository.DeleteCodeEntity<Employee>(code, context))
                {
                    return new ServiceResult(false);
                }
                return new ServiceResult(EntityRepository.Commit(context));
            }
        }

        public SingleResult<Employee> GetEmployee(Guid id)
        {
            using (OrganizationDbContext context = new OrganizationDbContext())
            {
                return new SingleResult<Employee>(EntityRepository.GetCodeEntity<Employee>(id, context));
            }
        }

        public SingleResult<Employee> GetEmployee(string code)
        {
            using (OrganizationDbContext context = new OrganizationDbContext())
            {
                return new SingleResult<Employee>(EntityRepository.GetCodeEntity<Employee>(code, context));
            }
        }
    }
}
